<!--
	作者：956911785@qq.com
	时间：2019年11月20日18:42:04
	描述：学生-添加
-->

<template>
	<Modal :title="title" v-model="modal0" width="800px">
		<Form ref="params" :model="params" :rules="ruleValidate" :label-width="100" label-position="left">
			<div style="width:100%;height:200px; overflow-y: scroll;">
		        <div style="width:100%;height: 60px;line-height: 60px;float:left;">
		        	<div style="width: 50%;text-align: left;float: left;" align="left">
				        <FormItem  prop="sname" label="学生姓名">
				        	<Input v-model.trim="params.sname" placeholder="请输入学生姓名" clearable style="width: 70%"></Input>
		        		</FormItem>
		        	</div>
		        	<div style="width: 50%;text-align: left;float: left;" align="left">
				        <FormItem  prop="sfzh" label="身份证号">
				        	<Input v-model.trim="params.sfzh" placeholder="请输入身份证号" clearable style="width: 70%"></Input>
		        		</FormItem>
		        	</div>
		        </div>
		        
		        <div style="width:100%;height: 60px;line-height: 60px;float:left;">
		        	<div style="width: 50%;text-align: left;float: left;" align="left">
				        <FormItem  prop="nj" label="年级">
				        	<InputNumber :max="10" :min="1" v-model="params.nj" style="width: 70%"></InputNumber>
		        		</FormItem>
		        	</div>
		        	<div style="width: 50%;text-align: left;float: left;" align="left">
				        <FormItem  prop="bj" label="班级">
				        	<InputNumber :max="10" :min="1" v-model="params.bj" style="width: 70%"></InputNumber>
		        		</FormItem>
		        	</div>
		        </div>
		     

				<div style="width:100%;height: 60px;line-height: 60px;float:left;">
		        	<div style="width: 50%;text-align: left;float: left;" align="left">
				        <FormItem  prop="jzsj" label="家长手机号码">
							<Input v-model.trim="params.jzsj" placeholder="请输入家长手机号码" clearable style="width: 70%"></Input>
		        		</FormItem>
		        	</div>	
		        </div>

		   </div> 
	    </Form>
	   	<div slot="footer">
	    	<Button type="text"  @click="closeModal()">取消</Button>
	    	<Button type="primary" @click="addsave()" >确定</Button>
	    </div>
     </Modal>
</template>

<script>
	export default {
		name:"addteacher",
		props: {
    		teas:{
    			type:Object,	
    			default: function() {
					return null
				}
    		},
    		title:{
    			type:String,	
    		},
    	},
		data() {
			//长度控制
			const lenPass = (rule, str, callback) => {
			  if(str.length>rule.length){
			  	 callback(new Error('字符串长度在1-'+rule.length+'之间！'));
			  }
			  return callback();
			};
			//身份证检验
		    const idCardPass = (rule, value, callback) => {
			  let reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/; 
			  if (value === '') {
			    callback(new Error('身份证号不能为空'));
			  }else if(!reg.test(value)){
			    callback(new Error('请输入正确的身份证号'));
			  }else{
			  	return callback();
			  }
			};
				//正整数控制
			const zzsPass1 = (rule, value, callback) => {
			    let reg = /^\+?[1-9][0-9]*$/; 
				if(!reg.test(value)){
				    callback(new Error('请输入正整数！'));
				}else{
				  	return callback();
				}
			};
			return {
				ruleValidate: {
		            sname: [
		                {required: true, message: '请输入学生姓名！', trigger: 'blur'},
		                {length:50,validator:lenPass,trigger:'blur'}
		            ],
		            sfzh: [{required: true, validator: idCardPass, trigger: "blur" , length:18}],
					jzsj: [
					    {required: true, message: '请输入家长手机号码！', trigger: 'blur'},
						{length:20,validator:lenPass,trigger:'blur'}, 
						{validator:zzsPass1,trigger:'blur'}
					], 
		      },   
                modal0:false,
                params:{
					sid:"",
					sname:"",
					sfzh:"",
					nj:1,
					bj:1,
					jzsj:'',
				},
			}
		},
		components: {
		},
		methods: {
			addsave:function(){
				this.$refs.params.validate((valid) => {
					if (valid){
						const params={...this.params};
						this.$emit("addsave",params);
                    }
               })
	        }, 
			
            closeModal(){
	      	    this.modal0 = false;
	      	    this.resetpar();
	        },
	        resetpar(){
	        	this.params={
	        		sid:"",
	        		sname:"",
	        		sfzh:"",
	        		nj:1,
	        		bj:1,
	        		jzsj:'',
				};
	        },
	        
		},
		mounted() {
		
  			
		},
		watch:{
			modal0(news,olds){
				if(!news){
					 this.resetpar();
				}else{
					this.params=this.teas;
				}
			}
		},
		computed: {
			
		}
		
	}
</script>

<style scoped="scoped">
	
</style>



